package com.by.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    // 订单队列
    @Bean
    public Queue orderQueue(){
        return new Queue(Constant.ORDER_QUEUE,true);
    }
    // 订单交换器
    @Bean
    public DirectExchange orderExchange(){
        return new DirectExchange(Constant.ORDER_EXCHANGE,true,false);
    }
    // 订单绑定
    @Bean
    public Binding orderBinding(){
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(Constant.ORDER_KEY);
    }

    /**
     * 延迟队列
     *
     * @return
     */
    @Bean
    public Queue lazyQueue() {
        return new Queue(Constant.LAZY_QUEUE);
    }

    /**
     * 延迟交换器
     *
     * @return
     */
    @Bean
    public LazyExchange lazyExchange() {
        return new LazyExchange(Constant.LAZY_EXCHANGE);
    }

    @Bean
    public Binding bindingLazy(LazyExchange lazyExchange, Queue lazyQueue) {
        return BindingBuilder.bind(lazyQueue).to(lazyExchange).with(Constant.LAZY_KEY).noargs();
    }

}
